# Create your views here.
import urllib, urllib2
import os, stat, time, sha, sys
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
import django.utils.simplejson as jsondata
#from xml2dict import fromstring
from activitystream.lib.xml2dict import fromstring

from conf.PicasaConf import PicasaConf
from PhotoData import PhotoData


def render(template, payload):        
    return render_to_response(template, payload)

def index(request):  
    pData = PhotoData()
    userAlbum = pData.getAlbum()    
    userTags = pData.getUserTag()
    latestPhotos = pData.getLatestPhotos()
    defaultAlbum = pData.getDefaultAlbum()
    defaultAlbumPhotos = pData.getAlbumPhotos(defaultAlbum)
    
    payload = dict(albumList = userAlbum, tagList = userTags, photoList = latestPhotos, albumPhotoList = defaultAlbumPhotos, userName = pData.getUserName())
    return render('photos.html', payload)

def photos(request,album_id):
    pData = PhotoData()
    userAlbum = pData.getAlbum()    
    userTags = pData.getUserTag()
    latestPhotos = pData.getLatestPhotos()    
    selectedAlbumPhotos = pData.getAlbumPhotos(album_id)
    
    payload = dict(albumList = userAlbum, tagList = userTags, photoList = latestPhotos, albumPhotoList = selectedAlbumPhotos, userName = pData.getUserName())
    return render('photos.html', payload)

def tagphotos(request,tag_name):
    pData = PhotoData()
    userAlbum = pData.getAlbum()    
    userTags = pData.getUserTag()
    latestPhotos = pData.getLatestPhotos()    
    selectedTagPhotos = pData.getTagPhotos(tag_name)
    
    payload = dict(albumList = userAlbum, tagList = userTags, photoList = latestPhotos, albumPhotoList = selectedTagPhotos, userName = pData.getUserName(), tagName = tag_name)
    return render('tag-photos.html', payload)
    